function checkPhone(val) {
  //手机号正则验证
  let reg = /^1[3456789]{1}\d{9}$/;
  if (reg.test(val)) {
    return true;
  } else {
    return false;
  }
}
function checkIdCard(id) {
  const regex =
    /^[1-9]\d{5}(18|19|20|21|22)?\d{2}(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])\d{3}(\d|[Xx])$/;
  if (id == "") {
    return "身份证号码不能为空";
  } else if (regex.test(id)) {
    return "";
  } else {
    return "请输入正确的身份证号码";
  }
}
function setMoney(val) {
  let num = Number(val);
  if (num >= 10000) {
    return num / 10000 + "w";
  } else {
    return num;
  }
}
function getDate(time) {
  if (!time) {
    return "";
  }
  const y = time.getFullYear();
  const m =
    time.getMonth() < 9 ? `0${time.getMonth() + 1}` : time.getMonth() + 1;
  const d = time.getDate() < 10 ? `0${time.getDate()}` : time.getDate();

  const str = `${y}-${m}-${d}`;
  return str;
}
function checkNumber(val) {
  if (val === "") {
    return "不能为空";
  } else {
    if (!/^\d+(\.\d+)?$/.test(val)) {
      return "需为纯数字";
    } else {
      return "";
    }
  }
}
export default {
  checkPhone,
  getDate,
  setMoney,
  checkNumber,
  checkIdCard,
};
